<?php

use think\migration\Migrator;
use think\migration\db\Column;

class ProjectCon extends Migrator
{
    /**
     * Change Method.
     *
     * Write your reversible migrations using this method.
     *
     * More information on writing migrations is available here:
     * http://docs.phinx.org/en/latest/migrations.html#the-abstractmigration-class
     *
     * The following commands can be used in this method and Phinx will
     * automatically reverse them when rolling back:
     *
     *    createTable
     *    renameTable
     *    addColumn
     *    renameColumn
     *    addIndex
     *    addForeignKey
     *
     * Remember to call "create()" or "update()" and NOT "save()" when working
     * with the Table class.
     */
    public function change()
    {
        $table = $this->table('project', ['comment' => '项目表']);
        $table->addColumn('project_name', 'string', array('limit' => 120, 'comment' => '项目名称'))
            ->addColumn('year', 'string', array('limit' => 120, 'comment' => '年份'))
            ->addColumn('template_id', 'integer', array('limit' => 30, 'default' => 1, 'comment' => '模版id'))
            ->addColumn('create_id', 'integer', array('limit' => 30, 'default' => 1, 'comment' => '创建人id'))
            ->addColumn('status', 'boolean', array('limit' => 1, 'default' => 1, 'null' => true, 'comment' => '是否开启（0关闭1开启）'))
            ->addTimestamps()
            ->addSoftDelete()
            ->addIndex(array('project_name'))
            ->create();

        $table = $this->table('project_type', ['comment' => '项目一级表']);
        $table->addColumn('project_type_name', 'string', array('limit' => 120, 'comment' => '项目一级名称'))
            ->addColumn('year', 'string', array('limit' => 120, 'comment' => '年份'))
            ->addColumn('project_id', 'integer', array('limit' => 30, 'default' => 1, 'comment' => '项目id'))
            ->addColumn('create_id', 'integer', array('limit' => 30, 'default' => 1, 'comment' => '创建人id'))
            ->addColumn('status', 'boolean', array('limit' => 1, 'default' => 1, 'null' => true, 'comment' => '是否开启（0关闭1开启）'))
            ->addTimestamps()
            ->addSoftDelete()
            ->addIndex(array('project_type_name'))
            ->create();


        $table = $this->table('project_second_level', ['comment' => '项目二级分类']);
        $table->addColumn('project_second_title', 'string', array('limit' => 320, 'null' => true,'comment' => '项目二级名称'))
            ->addColumn('year', 'string', array('limit' => 50,'null' => true, 'comment' => '年份'))
            ->addColumn('project_original_score', 'string', array('limit' => 50,'null' => true, 'comment' => '原始分值'))
            ->addColumn('project_explain', 'string', array('limit' => 320, 'null' => true,'comment' => '扣分说明'))
            ->addColumn('project_id', 'integer', array('limit' => 30, 'default' => 1, 'comment' => '项目id'))
            ->addColumn('project_type_id', 'integer', array('limit' => 30, 'default' => 1, 'comment' => '项目一级id'))
            ->addColumn('create_id', 'integer', array('limit' => 30, 'default' => 1, 'comment' => '创建人id'))
            ->addTimestamps()
            ->addSoftDelete()
            ->addIndex(array('project_second_title'))
            ->create();


        $table = $this->table('project_detail', ['comment' => '项目详情表']);
        $table->addColumn('project_detail_title', 'string', array('limit' => 320, 'null' => true,'comment' => '项目详情名称'))
            ->addColumn('year', 'string', array('limit' => 50, 'null' => true,'comment' => '年份'))
            ->addColumn('once_deduct_marks', 'string', array('limit' => 120, 'comment' => '单次扣分'))
            ->addColumn('most_deduct_marks', 'string', array('limit' => 120, 'comment' => '最多扣分'))
            ->addColumn('duty_unit_id', 'integer', array('limit' => 30, 'default' => 1, 'comment' => '责任单位id'))
            ->addColumn('project_id', 'integer', array('limit' => 30, 'default' => 1, 'comment' => '项目id'))
            ->addColumn('project_type_id', 'integer', array('limit' => 30, 'default' => 1, 'comment' => '项目一级id'))
            ->addColumn('project_second_level_id', 'integer', array('limit' => 30, 'default' => 1, 'comment' => '项目二级id'))
            ->addColumn('create_id', 'integer', array('limit' => 30, 'default' => 1, 'comment' => '创建人id'))
            ->addTimestamps()
            ->addSoftDelete()
            ->addIndex(array('project_detail_title'))
            ->create();
    }
}
